package com.coocaa.ops.admin.v1.panel.constant;

import com.coocaa.ops.plus.core.third.magic.model.AiIconInfoModel;
import com.coocaa.ops.common.tool.base.InstanceUtil;
import com.coocaa.ops.common.tool.json.JsonUtil;
import lombok.experimental.UtilityClass;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Iterator;
import java.util.List;

/**
 * @author bijiahao
 * @description
 * @date 2020/10/16 16:59
 */
@UtilityClass
public class AiIconConstants {

    public static final int TOTAL_WORD_NUMS = 14;

    public static final List<String> ICON_POSITIONS;


    static {
        ICON_POSITIONS= InstanceUtil.newArrayList();
        ICON_POSITIONS.add("left_top");
        ICON_POSITIONS.add("right_top");
        ICON_POSITIONS.add("left_bottom");
        ICON_POSITIONS.add("right_bottom");
    }

    public static String getFinalIconTextPositionsJsonStr(String iconTextPositionsJsonStr){
        if (StringUtils.isBlank(iconTextPositionsJsonStr)){
            return null;
        }
        List<AiIconInfoModel> aiIconInfoModelList = JsonUtil.json2ObjectLists(iconTextPositionsJsonStr, AiIconInfoModel.class);
        if(CollectionUtils.isEmpty(aiIconInfoModelList)){
            return null;
        }
        Iterator<AiIconInfoModel> it = aiIconInfoModelList.iterator();
        while (it.hasNext()){
            AiIconInfoModel aiIconInfoModel = it.next();
            if (null == aiIconInfoModel || StringUtils.isBlank(aiIconInfoModel.getIconText()) || StringUtils.isBlank(aiIconInfoModel.getPosition())){
                it.remove();
            }
        }
        if (CollectionUtils.isEmpty(aiIconInfoModelList)){
            return null;
        }
        return JsonUtil.obj2Json(aiIconInfoModelList);
    }

    public static void main(String[] args) {
        String res = getFinalIconTextPositionsJsonStr("[{},{},{},{}]");
        System.out.println(res);
    }
}

